package com.example.tangjiangxu.fragmentdemo2;

import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Toast;

import javax.security.auth.login.LoginException;

public class OneFragment extends Fragment {
    private static final String TAG = "OneFragment";

    /**
     * 点击的接口，需要实现点击的Actiivty, 实现该接口
     */
    public interface OnClickOneButtonListener {
        /**
         * 回调的方法
         */
        void onClickOneButton();

    }


    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        Log.e(TAG, "onAttach 1: ");
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        Log.e(TAG, "onAttach 2: ");
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        Log.e(TAG, "onCreateView: ");
        View view = inflater.inflate(R.layout.fragment_one, container, false);
        EditText one_et = (EditText) view.findViewById(R.id.one_et);
        Button bn = (Button) view.findViewById(R.id.bnt_tow);
        bn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //如果Fragment依附的Activity实现了{@link #OnClickTowButtonListener},则调用接口回调方法
                if (getActivity() instanceof OnClickOneButtonListener) {
                    ((OnClickOneButtonListener)getActivity()).onClickOneButton();
                }
            }
        });
        return view;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.e(TAG, "onDestroy: ");
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        Log.e(TAG, "onDestroyView: ");
    }

    @Override
    public void onDetach() {
        super.onDetach();
        Log.e(TAG, "onDetach: ");
    }


}
